package com.yiwei.hdb.impl;

import android.content.Context;

import com.yiwei.hdb.constant.Const;
import com.yiwei.hdb.http.CallBackListener;
import com.yiwei.hdb.http.InterfaceServer;
import com.yiwei.hdb.http.InfoCallBack;
import com.yiwei.hdb.interfaces.UploadImageInfo;
import com.yiwei.hdb.model.RequestModel;
import com.yiwei.hdb.model.ResponseModel;
import com.yiwei.hdb.model.UploadImageModel;

import java.util.HashMap;
import java.util.Map;

/**
 * 上传图片数据
 * Created by Master.Dong on 2016/4/13.
 */
public class UploadImageInfoImpl implements UploadImageInfo {

    /**
     * 上传图片
     *
     * @param mContext
     * @param img
     * @param callBack
     */
    @Override
    public void getUploadImageInfo(final Context mContext, String img, final InfoCallBack callBack) {
        Map<String, Object> mapData = new HashMap<String, Object>();
        mapData.put("img", img);
        RequestModel model = new RequestModel(mapData);

        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.UPLOAD_IMAGE, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT,new CallBackListener<UploadImageModel>(UploadImageModel.class,callBack));
//                new ResponseListener() {
//            @Override
//            public void onStartInMainThread(Object result) {
//                callBack.onFailure(result.toString());
//            }
//
//            @Override
//            public void onFinishInMainThread(Object result) {
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<UploadImageModel>fromJson(content, UploadImageModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//
//            @Override
//            public void onSuccessInMainThread(int statusCode, String content, Object result) {
//                try {
//                    UploadImageModel model = (UploadImageModel) result;
//
//                    callBack.onSuccess(model);
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
    }

    /**
     * 上传颜值照片
     *
     * @param mContext
     * @param img
     * @param callBack
     */
    @Override
    public void getUploadFaceImgInfo(Context mContext, String img, final InfoCallBack callBack) {
        Map<String, Object> mapData = new HashMap<String, Object>();
        mapData.put("img", img);
        RequestModel model = new RequestModel(mapData);

        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.UPLOAD_PHOTO, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT, new CallBackListener<ResponseModel>(ResponseModel.class,callBack));
//                new ResponseListener() {
//            @Override
//            public void onStartInMainThread(Object result) {
//                callBack.onFailure(result.toString());
//            }
//
//            @Override
//            public void onFinishInMainThread(Object result) {
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<ResponseModel>fromJson(content, ResponseModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//
//            @Override
//            public void onSuccessInMainThread(int statusCode, String content, Object result) {
//                try {
//                    ResponseModel model = (ResponseModel) result;
//
//                    if (model.getStatus() == 1)
//                        callBack.onSuccess(model);
//                    else callBack.onFailure(model.getMsg());
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
    }

}
